import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': path.resolve(process.cwd(), 'src')
    }
  },
  server: {
    host: '0.0.0.0',
    port: 3000,
    open: true, // 运行自动打开浏览器
    proxy: {
      [process.env.VITE_APP_BASE_API]: {
        // 本地API地址
        target: 'http://localhost:8080',
        changeOrigin: true,
        rewrite: path => path.replace(new RegExp('^' + process.env.VITE_APP_BASE_API), '')
      },
      [process.env.VITE_APP_BASE_WEBSOCKET]: {
        // 本地API地址
        target: 'ws://localhost:8080',
        changeOrigin: true,
        rewrite: path => path.replace(new RegExp('^' + process.env.VITE_APP_BASE_WEBSOCKET), '')
      }
    }
  },
})
